from selenium.webdriver import ActionChains
from hyrobot.common import STEP, CHECK_POINT, INFO
from lib.webui_permission import *
import pyautogui
import pytest
import time
import json
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By


class c73254d1:
    # use zhangsan,test turn page need LJY id
    name = '产品管理员验证所有界面存在且可操作产品管理查询新增部分-c73254d1'  # 测试用例名字

    # 初始化方法
    def setup(self):
        STEP(1, '登陆网站')
        driver = open_browser()
        productor1_login(driver)

    # 清除方法
    def teardown(self):
        driver = get_global_webdriver()
        driver.quit()

    # 测试用例步骤
    def teststeps(self):
        # 获取webdriver对象 对应 已经登录好的浏览器
        driver = get_global_webdriver()
        # driver = webdriver.Firefox()

        extending_button = driver.find_element_by_id("hamburger-container")
        try:
            driver.find_element(By.CLASS_NAME, "el-tooltip")
            extending_button.click()
        except:
            print("左侧栏没有隐藏")
        # click product manage
        time.sleep(1)
        product_manage_word2 = driver.find_element(By.XPATH,
                                                   "/html/body/div/div/div[1]/ul/div[3]/a/li/span"
                                                       )
        product_manage_word2.click()
        time.sleep(1)
        top_title2 = driver.find_element(By.XPATH,
                                         "/html/body/div/div/div[2]/div/div/div[2]/span/span[2]/span[1]/span"
                                          ).text
        CHECK_POINT("上方第3个标题对应", "产品管理" == top_title2)

        # STEP(2, "页面跳转")
        # turn_page(driver)

        STEP(3, "查询两个空")
        time.sleep(1)
        driver.find_element(By.XPATH,
        "/html/body/div[1]/div/div[2]/section/div[1]/div/div/div[2]/form/div[3]/div/button/span"
                            ).click()
        # get table row num
        table_loc = driver.find_element(By.XPATH,
        "/html/body/div[1]/div/div[2]/section/div[1]/div/div/div[2]/div[1]"
                                        )
        # 按行查询表格的数据，取出的数据是一整行，按空格分隔每一列的数据
        table_tr_list = table_loc.find_elements(By.TAG_NAME, 'tr')
        table_row_num = len(table_tr_list)
        INFO(table_row_num)
        CHECK_POINT("检查行数是否不为0", table_row_num > 0)

        STEP(4, "输入一条存在产品名称，项目名称的记录信息点击查询")
        product_name = "NAME--34"
        uploader_name = "李俊沂"
        select_message_list(driver, product_name, uploader_name)
        time.sleep(1)
        got_db_manager_list = get_colum(driver,2)
        CHECK_POINT("上传人提示信息是否一致", got_db_manager_list == uploader_name)

        STEP(5, "新增产品")
        add_product(driver)





